package com.piggy.im.mq.model;

import com.alibaba.fastjson.JSON;
import com.piggy.im.domain.bo.SmsMessage;
import com.piggy.im.domain.bo.SysPublishMsgBo;
import com.piggy.mq.enums.MQSendTypeEnum;
import com.piggy.mq.model.AbstractMQ;
import lombok.*;
import lombok.experimental.Accessors;
import org.springframework.amqp.core.ExchangeTypes;

import java.util.Map;

@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class SmsMsgMQ extends AbstractMQ {

    /** 【！重要配置项！】 定义MQ名称 **/
    public static final String MQ_NAME = "sms.msg.mq";

    /** 【！重要配置项！】 定义MQ名称 **/
    public static final String EXCHANGE_NAME = "sms.msg.exchange";

    /** 内置msg 消息体定义 **/
    private SmsMessage payload;

    @Override
    public String getMQName() {
        return MQ_NAME;
    }

    @Override
    public MQSendTypeEnum getMQType() {
        return MQSendTypeEnum.BROADCAST;
    }

    @Override
    public String getExchangeName() {
        return EXCHANGE_NAME;
    }

    @Override
    public String getExchangeType() {
        return ExchangeTypes.TOPIC;
    }

    @Override
    public String routingKey() {
        return "*";
    }

    @Override
    public String toMessage() {
        return JSON.toJSONString(payload);
    }

    @Override
    public Map<String, Object> getMQArgs() {
        return null;
    }


    /** 解析MQ消息， 一般用于接收MQ消息时 **/
    public static SmsMessage parse(String msg){
        return JSON.parseObject(msg, SmsMessage.class);
    }
}
